package cn.billy.system.controller;

import cn.billy.basic.utils.AjaxResult;
import cn.billy.basic.utils.PageList;
import cn.billy.org.domain.Department;
import cn.billy.org.query.DepartmentQuery;
import cn.billy.system.domain.SystemDictionaryType;
import cn.billy.system.query.SystemQuery;
import cn.billy.system.service.ISystemTypeService;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/systemtype")
public class SystemTypeController {

    @Autowired
    private ISystemTypeService iSystemTypeService;

    @GetMapping
    public List<SystemDictionaryType> loadAll(){
        return iSystemTypeService.loadAll();
    }

    @GetMapping("/{id}")
    public SystemDictionaryType getById(@ApiParam(value="部门主键",required = true)  @PathVariable("id") Long id){
        return iSystemTypeService.getById(id);
    }

    @PostMapping
    public PageList<SystemDictionaryType> queryData(@RequestBody SystemQuery systemQuery){
        PageList<SystemDictionaryType> data = iSystemTypeService.queryData(systemQuery);
        return data;
    }

    @DeleteMapping("/{id}")
    public AjaxResult remove(@PathVariable("id") Long id){
        try {
            iSystemTypeService.remove(id);
            return AjaxResult.me();
        } catch (Exception e){
            e.printStackTrace();
            return AjaxResult.me().setSuccess(false).setMessage("系统繁忙，请稍后再试！");
        }
    }

    @PutMapping
    public AjaxResult addOrUpt(@RequestBody SystemDictionaryType systemDictionaryType){
        try {
            if (systemDictionaryType.getId() == null){
                iSystemTypeService.save(systemDictionaryType);

            } else {
                iSystemTypeService.update(systemDictionaryType);
            }
            return AjaxResult.me();
        } catch (Exception e) {
            e.printStackTrace();
            return AjaxResult.me().setSuccess(false).setMessage("系统繁忙，请稍后再试！");
        }

    }
    @PatchMapping
    public AjaxResult batchDel(@RequestBody Long[] ids){
        try {
            iSystemTypeService.batchDel(ids);
            return AjaxResult.me();
        } catch (Exception e){
            e.printStackTrace();
            return AjaxResult.me().setSuccess(false).setMessage("系统繁忙，请稍后再试！");
        }
    }
}
